'''
定义了黑客所用的随机函数
尽管有些已经在Scapy中实现了，但这些函数性能更好

Define the random function which used by hacks.
Though some are already defined in the Scapy, these function are faster.
'''

#############
#引入 # import#
#############

from random import randint, choice, randbytes
from time import sleep

##########################
#随机函数 # random functions#
##########################

def randhex() -> str:
    '''
    返回一个随机的十六进制数

    return a random hex number
    '''
    return choice(
        ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f')
    )

def randip() -> str:
    '''
    返回一个随机的IPv4地址

    return a random IPv4 address
    '''
    return '.'.join(
            [str(randint(0, 225)) for i in range(3)] + [str(randint(1, 225))]
        )

def randmac() -> str:
    '''
    返回一个随机的MAC地址

    return a random mac address
    '''
    return ':'.join(
        (randhex()+randhex() for i in range(6))
    )

def randport(min:int=1, max:int=65535) -> int:
    '''
    返回一个随机的端口，端口范围在min到max之间

    return a random port
    port number range from min to max
    '''
    return randint(1, 65535)

def randttl(min:int=128, max:int=225) -> int:
    '''
    返回一个随机的ttl
    ttl 即 “time to live”（存活时间）
    ttl在min到max之间

    return a random ttl
    ttl is "time to live"
    ttl range from min to max
    '''
    return randint(128, 225)

def randsleep(min:int=1, max:int=100, devide:int=100) -> None:
    '''
    随机阻塞一段时间
    范围为min/devide秒到max/devide秒

    sleep a random time which range from min/devide(s) to max/devide(s)
    '''
    sleep(randint(min, max)/devide)

def randwindow(min:int=1, max:int=65535) -> int:
    '''
    返回随机的window size，其值介于min和max之间

    return a random window size range from min to max
    '''
    return randint(min, max)

def randLAN():
    '''
    返回随机的局域网ip
    '''
    return 